package com.hktf.moedokilock.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hktf.corelib.utils.CommUtils;
import com.hktf.corelib.utils.UIUtils;
import com.hktf.moedokilock.R;
import com.hktf.moedokilock.bean.MainItem;
import com.hktf.uilib.bean.lock.WidgetItem;
import com.hktf.uilib.utils.ImageUtilNew;

import java.util.List;

/**
 * @包名称： com.cdz.bluetooth.adapter
 * @类名： BluetoothViewAdapter
 * @创建人： 陈大专
 * @时间： 2021/08/17 14:06
 * @描述：
 */
public class WidgetItemAdapter extends BaseMultiItemQuickAdapter<WidgetItem, BaseViewHolder> {
    public WidgetItemAdapter(@Nullable List<WidgetItem> data) {
        super(data);
        addItemType(WidgetItem.TYPE_EMPTY,R.layout.widget_empty_item);
        addItemType(WidgetItem.TYPE_TITLE,R.layout.widget_title_item);
        addItemType(WidgetItem.TYPE_TEXT1, R.layout.widget_text_item);
        addItemType(WidgetItem.TYPE_TEXT2, R.layout.widget_text_item_weight2);
        addItemType(WidgetItem.TYPE_GIF,R.layout.widget_gif_item);
        addItemType(WidgetItem.TYPE_JITANG,R.layout.widget_text_item_weight2);
        addItemType(WidgetItem.TYPE_TEXT_CIRCLE,R.layout.widget_text_circle_item);
    }

    private boolean showDelete;
    private boolean showLine=true;

    public boolean isShowLine() {
        return showLine;
    }

    public void setShowLine(boolean showLine) {
        this.showLine = showLine;
    }

    public boolean isShowDelete() {
        return showDelete;
    }

    public void setShowDelete(boolean showDelete) {
        this.showDelete = showDelete;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, WidgetItem item) {
        helper.setGone(R.id.fl_delete,showDelete);
        if (showDelete) {
            helper.addOnClickListener(R.id.fl_delete);
        }
        switch (item.getItemType()){
            case WidgetItem.TYPE_EMPTY://空白
                helper.setGone(R.id.fl_delete,false);
                break;
            case WidgetItem.TYPE_TITLE://标题
                helper.setImageResource(R.id.iv,item.getIconResId());
                helper.setText(R.id.tv,item.getTitle());

                break;
            case WidgetItem.TYPE_TEXT1://文本1
                helper.setGone(R.id.line,showLine);
                helper.setText(R.id.tv,item.getTitle());
                break;
            case WidgetItem.TYPE_TEXT2://文本2
                helper.setGone(R.id.line,showLine);
                helper.setText(R.id.tv,item.getTitle());
                break;
            case WidgetItem.TYPE_GIF://gif
                helper.setGone(R.id.line,showLine);
                ImageView iv=helper.getView(R.id.iv);
//                ImageUtilNew.loadImageFitXY(iv.getContext(),item.getIconResId(),
//                        UIUtils.getDimen(com.hktf.uilib.R.dimen.gif_widget_width),UIUtils.getDimen(com.hktf.uilib.R.dimen.widget_height),iv);
                ImageUtilNew.loadImage(iv.getContext(),item.getIconResId(),iv);
                break;
            case WidgetItem.TYPE_JITANG://鸡汤
                helper.setGone(R.id.line,showLine);
                helper.setText(R.id.tv,item.getTitle());
                break;
            case WidgetItem.TYPE_TEXT_CIRCLE://圆形背景文本
                helper.setGone(R.id.line,showLine);
                helper.setText(R.id.tv,item.getTitle());
                break;
        }

    }
}
